const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      pickerOptions: pickerOptions,
      rules: {
        Brand_Name: [{
          required: true,
          message: '请输入品牌名称',
          trigger: 'blur',
        }]
      },
      form: {
        Brand_SerialNumber: "",
        Brand_Name: '',
        Row_Status: '',
        Operation_ID: '',
        Operation_Datetime: '',
      },
      loading: false
    }
  },
  mounted() {
    const Brand_SerialNumber = sessionStorage.getItem("Brand_SerialNumber")
    this.getData(Brand_SerialNumber)
  },
  methods: {
    getData(Brand_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/ShopBrand_Original',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          console.log('根据品牌流水获取结果', res)
          for (let i = 0; i < res.length; i++) {
            if (res[i].Brand_SerialNumber == Brand_SerialNumber) {
              _this.form = res[i];
            }
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const { add, modify } = _this.deal()
          let data = {}
          if (add == null) {
            data = { Data: JSON.stringify({ Modify: { brand: [modify] } }) }
          } else {
            data = {
              Data: JSON.stringify(
                {
                  Modify: { brand: [modify] },
                  Add: { brand: [add] }
                }
              )
            }
          }
          _this.loading = true
          $.ajax({
            url: DomainName + '/GoodsFileEdit',
            type: 'POST',
            data: data,
            success: function (res) {
              console.log('提交结果', res)
              _this.$message.success("提交成功")
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    deal() {
      const modify = deepClone(this.form)
      return { add: null, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
})